package com.shcz.migu.app;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;
import android.util.DisplayMetrics;

import com.orhanobut.logger.Logger;
import com.shcz.migu.preference_config.PreferenceUtil;
import com.shcz.migu.utils.CommonUtils;
import com.shcz.migu.utils.Constants;
import com.shcz.migu.utils.DisplayUtils;


public class App extends Application {
    private static DisplayMetrics dm = new DisplayMetrics();

    private static App instance;

    public static App getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        initLocalData();
        System.loadLibrary("gnustl_shared");
        System.loadLibrary("qupai-media-thirdparty");
        System.loadLibrary("qupai-media-jni");
//        ApplicationGlue.initialize(this);
        instance = this;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);

    }


    private void initLocalData() {
//        CommonToast.init(this);
        CommonUtils.init(this);
        PreferenceUtil.init(this);
        DisplayUtils.init(this);
        Logger.init("LOGER");
        String info = "android(" + android.os.Build.VERSION.RELEASE + ";" + android.os.Build.MODEL + ")";//android(6.0;Nexus5)
        PreferenceUtil.commitString(Constants.ANDROID_INFO, info);
//        Logger.i("初始化ffmpeg");
        Mp3AudioConvert();
        initDataBase();//初始化数据库;
    }

    private void Mp3AudioConvert() {
//        AndroidAudioConverter.load(this, new ILoadCallback() {
//            @Override
//            public void onSuccess() {
//                // Great!
//                Logger.i("onSuccess");
//            }
//
//            @Override
//            public void onFailure(Exception error) {
//                // FFmpeg is not supported by device
//                Logger.i("onFailure");
//                error.printStackTrace();
//            }
//        });
    }

    private void initDataBase() {
//        DBUploadHelper.init(this);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    public static DisplayMetrics getDisplayMetrics(Activity activity) {
        if (dm == null || dm.widthPixels == 0) {
            if (activity != null) {
                activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
            }
        }
        return dm;
    }
}
